/**
 * @param {number[]} a
 * @return {number[]}
 */
var constructArr = function(a) {
  let result = new Array(a.length).fill(1);
  let len = a.length;
  let left = 1;
  // 计算右边
  for (let i = 0; i < len; i++) {
    if(i > 0 ) {
      result[i] = result[i - 1] * a[i - 1];
    }
  }
  let right = 1;
  for (let j = len - 1; j >= 0; j--) {
    if(j < len - 1) {
      right *= a[j + 1];
    }
    result[j] *= right;
  }
  console.log(result)
};

// constructArr([1,2,3,4]);
constructArr([7, 2, 2, 4, 2, 1, 8, 8, 9, 6, 8, 9, 6, 3, 2, 1]);

// [2006581248,1003290624,1003290624,501645312,1003290624,2006581248,250822656,250822656,222953472,334430208,250822656,222953472,334430208,668860416,1003290624,2006581248]
// [286654464,1003290624,1003290624,501645312,1003290624,2006581248,250822656,250822656,222953472,334430208,250822656,222953472,334430208,668860416,1003290624,2006581248]